﻿using System;
using Autodesk.Revit.DB;

namespace YArchitech.HVAC
{
	internal class SetLineType
	{
		public static ElementId ReturnLineStyleId(Autodesk.Revit.DB.Document doc, DetailCurve detailCurve, string newLineStyleName)
		{
			ElementId elementId = null;
			foreach (ElementId elementId2 in detailCurve.GetLineStyleIds())
			{
				Element element = doc.GetElement(elementId2);
				if (element.Name == newLineStyleName)
				{
					elementId = element.Id;
					break;
				}
			}
			if (elementId == null)
			{
				using (SubTransaction subTransaction = new SubTransaction(doc))
				{
					subTransaction.Start();
					Category category = doc.Settings.Categories.get_Item(BuiltInCategory.OST_Lines);
					doc.Settings.Categories.NewSubcategory(category, newLineStyleName).SetLineWeight(1, (Autodesk.Revit.DB.GraphicsStyleType)1);
					subTransaction.Commit();
				}
				doc.Regenerate();
				foreach (ElementId elementId3 in detailCurve.GetLineStyleIds())
				{
					Element element2 = doc.GetElement(elementId3);
					if (element2.Name == newLineStyleName)
					{
						elementId = element2.Id;
						break;
					}
				}
			}
			return elementId;
		}
	}
}
